<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


/**
 * 用户策略模型
 * @author Cavlin
 */
class MY_model extends CI_Model{
    //表名
    const TB_USER = "user";
    const TB_VERIFY = "u_verify";
    const TB_CHECK_LOG = "u_check_log";
    const TB_LOGIN_LOG = "u_login_log";
    const TB_USER_FILES = "u_files";
    const TB_OAUTH_USER = "oauth_user";
    const TBL_FOLDER = "user";
    const TB_USER_FOLDERS="u_folders";
    const TB_FILE_TYPE="file_type";
    const TB_USER_POLICIES="u_policies";
    const TB_USER_POLICIES_LOOKERS="u_policy_lookers";


    const TB_SOURCE_FILES="source_files";
    const TB_USER_SECURE_FILES="u_secure_files";
    const TB_FILE_TRACES="file_traces";

    const TB_SHARE_LINK = 'u_share_link';
    const TB_SHARE_LIST = 'u_share_list';
    const TB_FILE = 'u_files';
    const TB_FOLDER = 'u_folders';
    const TB_SECURE_FILES = 'u_secure_files';


    const TB_SHARE_RECEIVERS = 'u_share_receivers';

    const TB_APP_DIGEST = "app_digest";



    public function __construct($group_name='')
    {
        parent::__construct();
        //$this->load->database();
        $this->init_db($group_name);
        $this->trans_start();
    }

    private function init_db($group_name = '')
    {
        $db_conn_name = $this->get_db_name($group_name);
        $CI = & get_instance();
        if(isset($CI->{$db_conn_name}) && is_object($CI->{$db_conn_name})) {
            $this->db = $CI->{$db_conn_name};
        } else {
            $CI->{$db_conn_name} = $this->db = $this->load->database($group_name, TRUE);
        }
    }
    private function get_db_name($group_name = '')
    {
        if($group_name == '') {
            $db_conn_name = 'db';
        } else {
            $db_conn_name = 'db_'.$group_name;
        }
        return $db_conn_name;
    }

    public function trans_start()
    {
        $this->db->trans_start();
    }

    public function trans_complete()
    {
        $this->db->trans_complete();
    }


    public function __destruct()
    {
        $this->trans_complete();
    }
}